package com.test.springai.config;

import com.fasterxml.jackson.annotation.JsonClassDescription;
import java.util.function.Function;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 8/19/25 10:28 AM
 * @modifiedBy:
 * @version: 1.0
 */
@Slf4j
@Configuration
public class CalculatorService {
  @JsonClassDescription("通过输入两个加数a和b获取和")
  public record AddOperation(int a, int b) {}

  @JsonClassDescription("通过输入两个乘数a和b获取积")
  public record MulOperation(int a, int b) {}

  @Bean(name = "addFunction")
  @Description("加法运算")
  public Function<AddOperation, Integer> addFunction() {
    return request -> {
      log.info("Received AddOperation request: a={}, b={}", request.a, request.b);
      return request.a + request.b;
    };
  }

  @Bean(name = "mulFunction")
  @Description("乘法运算")
  public Function<MulOperation, Integer> mulFunction() {
    return request -> {
      log.info("Received MulOperation request: a={}, b={}", request.a, request.b);
      return request.a * request.b;
    };
  }
}
